package main;

import javax.media.j3d.Appearance;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Group;
import javax.media.j3d.Material;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JFrame;
import javax.vecmath.Color3f;
import javax.vecmath.Vector3f;

import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.image.TextureLoader;

public class MyDesk {
	
	private JFrame jf = null;
	
	public MyDesk(JFrame jf){
		this.jf = jf;
	}
	
	public BranchGroup generateDesk(){
		BranchGroup desk=new BranchGroup();
		
		TransformGroup deskTrans = new TransformGroup();
		deskTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		deskTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		deskTrans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
		
		Appearance ap_d=new Appearance();
		Material material_d=new Material();
		material_d.setDiffuseColor(new Color3f(1.0f,1.0f,1.0f));
		ap_d.setMaterial(material_d);
		
		System.out.println("Loading pcd1 texture");
		TextureLoader texLoader=new TextureLoader("./images/pcd1.jpg",jf);
		ap_d.setTexture(texLoader.getTexture());
		
		Appearance ap_d1=new Appearance();
		Material material_d1=new Material();
		material_d1.setDiffuseColor(new Color3f(1.0f,1.0f,1.0f));
		ap_d1.setMaterial(material_d1);
		
		System.out.println("Loading pcd2 texture");
		TextureLoader texLoader1=new TextureLoader("./images/pcd2.jpg",jf);
		ap_d1.setTexture(texLoader1.getTexture());
		
		Appearance ap_d2=new Appearance();
		Material material_d2=new Material();
		material_d2.setDiffuseColor(new Color3f(1.0f,1.0f,1.0f));
		ap_d2.setMaterial(material_d2);
		
		System.out.println("Loading pcd3 texture");
		TextureLoader texLoader2=new TextureLoader("./images/pcd3.jpg",jf);
		ap_d2.setTexture(texLoader2.getTexture());
		
	
		Transform3D t=new Transform3D();
		t.setTranslation(new Vector3f(-0.3f,-0.3f,0.0f));
		TransformGroup g=new TransformGroup(t);
		/*g.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		g.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		g.setCapability(TransformGroup.ENABLE_PICK_REPORTING);*/
		g.addChild(new Box(0.1f,0.1f,0.15f,Primitive.GENERATE_TEXTURE_COORDS,ap_d));
		
		t=new Transform3D();
		t.setTranslation(new Vector3f(-0.3f,-0.16f,0.0f));
		TransformGroup g1=new TransformGroup(t);
		/*g1.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		g1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		g1.setCapability(TransformGroup.ENABLE_PICK_REPORTING);*/
		g1.addChild(new Box(0.1f,0.04f,0.15f,Primitive.GENERATE_TEXTURE_COORDS,ap_d1));
		 
		t=new Transform3D();
		t.setTranslation(new Vector3f(0.0f,-0.1f,0.0f));
		TransformGroup g2=new TransformGroup(t);
		/*g2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		g2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		g2.setCapability(TransformGroup.ENABLE_PICK_REPORTING);*/
		g2.addChild(new Box(0.4f,0.02f,0.15f,Primitive.GENERATE_TEXTURE_COORDS,ap_d2));
			
		t=new Transform3D();
		t.setTranslation(new Vector3f(0.3f,-0.16f,0.0f));
		TransformGroup g3=new TransformGroup(t);
		/*g3.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		g3.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		g3.setCapability(TransformGroup.ENABLE_PICK_REPORTING);*/
		g3.addChild(new Box(0.1f,0.04f,0.15f,Primitive.GENERATE_TEXTURE_COORDS,ap_d1));
		
		t=new Transform3D();
		t.setTranslation(new Vector3f(0.225f,-0.3f,0.0f));
		TransformGroup g4=new TransformGroup(t);
		/*g4.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		g4.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		g4.setCapability(TransformGroup.ENABLE_PICK_REPORTING);*/
		g4.addChild(new Box(0.01f,0.1f,0.15f,Primitive.GENERATE_TEXTURE_COORDS,ap_d2));
		
		t=new Transform3D();
		t.setTranslation(new Vector3f(0.375f,-0.3f,0.0f));
		TransformGroup g5=new TransformGroup(t);
		/*g5.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		g5.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		g5.setCapability(TransformGroup.ENABLE_PICK_REPORTING);*/
		g5.addChild(new Box(0.01f,0.1f,0.15f,Primitive.GENERATE_TEXTURE_COORDS,ap_d2));
		
		t=new Transform3D();
		t.setTranslation(new Vector3f(0.31f,-0.37f,0.0f));
		TransformGroup g6=new TransformGroup(t);
		/*g6.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		g6.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		g6.setCapability(TransformGroup.ENABLE_PICK_REPORTING);*/
		g6.addChild(new Box(0.075f,0.01f,0.15f,Primitive.GENERATE_TEXTURE_COORDS,ap_d2));
		 
		t=new Transform3D();
		t.setTranslation(new Vector3f(0.0f,-0.18f,0.0f));
		TransformGroup g7=new TransformGroup(t);
		/*g7.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		g7.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		g7.setCapability(TransformGroup.ENABLE_PICK_REPORTING);*/
		g7.addChild(new Box(0.2f,0.01f,0.15f,Primitive.GENERATE_TEXTURE_COORDS,ap_d2)); 
		
	
		
		deskTrans.addChild(g);
		deskTrans.addChild(g1);
		deskTrans.addChild(g2);
		deskTrans.addChild(g3);
		deskTrans.addChild(g4);
		deskTrans.addChild(g5);
		deskTrans.addChild(g6);
		deskTrans.addChild(g7);
		
		desk.addChild(deskTrans);
		
		return desk;
	}
}
